<template>
  <div>
    <div class="info"></div>
    <div class="info_title">商品信息</div>
    <div class="box">
      <div class="imgdiv">
        <img alt="cover" :src="videoInfo.cover_img" />
      </div>
      <div class="textdiv">
        <p class="c_ctitle">{{ videoInfo.title }}</p>
        <p class="price">{{ videoInfo.price / 100 }}</p>
      </div>
    </div>
    <div class="footer">
      <p class="money">实付：{{ (videoInfo.price / 100).toFixed(2) }}</p>
      <p class="submit" @click="pay">立刻支付</p>
    </div>
  </div>
</template>

<script>
import { getVideoDetail, saveOrder } from "@/api/getData.js";
export default {
  data() {
    return {
      videoInfo: {},
    };
  },
  methods: {
    //获取视频详情
    async getDetail(vid) {
      try {
        const result = await getVideoDetail(vid);
        if (result.data.code === 0) {
          this.videoInfo = result.data.data;
        }
      } catch (err) {
        console.log(err);
      }
    },

    async pay() {
      try {
        const result = await saveOrder(
          this.$store.state.token,
          this.$route.query.video_id    //$route是路由
        );
        if (result.data.code === 0) {
          const toast = this.$createToast({
            txt: "购买成功",
            type: "correct",
            time: 1500,
            onTimeout: () => {
              this.$router.push({ path: "/order" });    //$router是整个对象
            },
          });
          toast.show();
        }
      } catch (err) {
        console.log(err);
      }
    },
  },
  mounted() {
    this.getDetail(this.$route.query.video_id);
  },
};
</script>

<style lang="scss" scoped>
// 视频标题
.info_title {
  padding: 10px 20px;
  background-color: #fff;
  border-bottom: 1px solid #d9dde1;
}
.box {
  background-color: #fff;
  box-sizing: border-box;
  padding: 20px;
  display: flex;
  margin-bottom: 15px;
  .imgdiv {
    width: 105px;
    height: 59px;
    flex-shrink: 0;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .textdiv {
    margin-left: 20px;
    height: 59px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    .price {
      flex-shrink: 0;
    }
  }
}
//底部
.footer {
  position: fixed;
  bottom: 0;
  width: 100%;
  height: 50px;
  background-color: #fff;
  display: flex;
  justify-content: space-between;
  box-shadow: 0 -2px 4px 0 rgba(0, 0, 0, 0.1);
  font-size: 16px;
  .money {
    height: 50px;
    line-height: 50px;
    flex: 2;
    text-align: center;
    background-color: #fff;
  }
  .submit {
    height: 50px;
    line-height: 50px;
    flex: 1;
    text-align: center;
    background-color: #ff2d50;
    color: #fff;
  }
}
</style>